package main.java.Fzy.Test;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Scanner;

public class demo_01 {
    public static void main(String[] args) {
        demo_01 demo_01 = new demo_01();
        System.out.println(demo_01.test02());
    }

    public int test(){
        Scanner sc = new Scanner(System.in);

        String text1 = sc.nextLine();
        String text2 = sc.nextLine();

        String[] arr1 = text1.split("\\.");
        String[] arr2 = text2.split("\\.");

        for (int i = 0; i < 3; i++) {

            if(arr1[i].length()>1){
                break;
            }
            if(arr2[i].length()>1){
                break;
            }

            int i1 = Integer.parseInt(arr1[i]);
            int i2 = Integer.parseInt(arr2[i]);
            if(i1>i2){
                return 1;
            }
        }
        return -1;
    }

    public int test02(){
        Scanner sc = new Scanner(System.in);
        BigDecimal bigDecimal = new BigDecimal(sc.nextInt());
        BigDecimal pow = bigDecimal.pow(sc.nextInt());
        BigDecimal remainder = pow.remainder(BigDecimal.valueOf(sc.nextInt()));
        System.out.println(remainder);
        return remainder.intValue();
    }

    public String test03(){
        HashMap<Integer,String> map = new HashMap<>();
        map.put(1,"YiDui");
        map.put(2,"LiangDui");
        map.put(3,"SanTiao");

        return "1";
    }
}
